#include <51func.h>
int main(int argc, char *argv[])
{
    //./9_mmap.c file1
    ARGS_CHECK(argc,2);
    // open
    int fd = open(argv[1],O_RDWR);
    ERROR_CHECK(fd,-1,"open");
    // 截断文件 ftruncate
    int ret = ftruncate(fd,5);
    ERROR_CHECK(ret,-1,"ftruncate");
    // 建立映射 mmap
    char *p = (char *)mmap(NULL,5,PROT_READ|PROT_WRITE,MAP_SHARED,
         fd,0);
    for(int i = 0; i < 5; ++i){
        printf("%c", p[i]);
    }
    printf("\n");
    p[4] = 'O';
    // 解除映射 munmap
    munmap(p,5);
    close(fd);
    return 0;
}

